"""
搜索商品 用例
"""
import os
import ddt
import unittest
from common.openExcel import Open_excel
from common.Base import open_browser
from Page.home_page import Home_page, home_url

fileName = os.path.dirname(__file__) + "/testData/搜索商品测试数据.xlsx"
testdata = Open_excel(fileName, "Sheet1", conversers={"goodname": str}).read()


@ddt.ddt
class SearchGoodsCase(unittest.TestCase):

    def setUp(self):
        # 打开浏览器 进入指定页面
        self.driver = open_browser()
        self.lp = Home_page(self.driver)
        self.lp.open_url(home_url)

    def tearDown(self):
        # 关闭浏览器
        self.lp.quit()

    def search_goods(self, goodname):
        self.lp.input_search(goodname)
        try:
            self.assertIn(goodname, self.lp.title(), msg="页面标题不包含输入数据")
            print(self.lp.title())
        except Exception as e:
            raise ("用例执行失败")

    @ddt.data(*testdata)
    def test_search_goods(self, data):
        self.search_goods(**data)


if __name__ == '__main__':
    unittest.main()
